package de.hpi.generator.model;

import java.util.ArrayList;

import de.hpi.generator.config.NotExistsException;

public class TablesCollection extends ArrayList<Table> {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    public Table findTableByName(String aTableName) throws NotExistsException {
        Table result = null;
        for (Table aTable : this) {
            if (aTable.getName().compareTo(aTableName) == 0) {
                result = aTable;
                break;
            }
        }
        if (result == null) {
            throw new NotExistsException("The table " + aTableName + " was not found in database");
        }

        return result;
    }

    public int getBiggestMinRowNumbers() {
        int result = 0;

        for (Table aTable : this) {
            int aMinRowNumbers = aTable.getMinRowNumbers();
            if (aMinRowNumbers > result) {
                result = aMinRowNumbers;
            }
        }

        return result;
    }
}